/* Author: Nahuel F. Lema, Maxi Yañez

 */

var voluntariosController = {

    validate: {

	get: function(){
	    var componentsPath = scriptsController.defs.baseUrl + scriptsController.defs.componentsPath + 'jvalidation/',
	    self = this;

	    $.getScript(componentsPath + 'jquery.validate.min.1.9.js', function(){
		self.bind();
	    });
	},

	bind: function(){
	    var form = $(js.get.item('#voluntarios-form')[0]);

	    $(js.get.item('#voluntario-btn')[0]).click(function(e){
		e.preventDefault();
		form.submit();
	    });

	    form.validate({
		rules: {
		    'nombre-field' : {
			required : true
		    },
		    'apellido-field': {
			required : true
		    },
		    'email-field' : {
			required : true,
			email	 : true
		    },
		    'telefono-field' : {
			required : true,
			number	 : true
		    },
		    'nacionalidad-field' : {
			required : true,
			minlength: 10
		    },
		    'dni-field' : {
			required : true,
			number	 : true
		    },
		    'calle-field' : {
			required : true
		    },
		    'altura-field' : {
			required : true
		    },
		    'piso-field' : {
			required : true
		    },
		    'estudios-field' : {
			required : true,
			minlength: 10
		    }
		},
		messages: {
		    'nombre-field' : {
			required : "Este campo es requerido"
		    },
		    'apellido-field': {
			required : "Este campo es requerido"
		    },
		    'email-field' : {
			required : "Este campo es requerido",
			email	 : "Ingrese un email valido"
		    },
		    'telefono-field' : {
			required : "Este campo es requerido",
			number	 : "Este campo solo pueden ser numeros"
		    },
		    'nacionalidad-field' : {
			required : "Este campo es requerido"
		    },
		    'dni-field' : {
			required : "Este campo es requerido",
			number	 : "Este campo solo pueden ser numeros"
		    },
		    'calle-field' : {
			required : "Este campo es requerido"
		    },
		    'altura-field' : {
			required : "Este campo es requerido"
		    },
		    'piso-field' : {
			required : "Este campo es requerido"
		    },
		    'estudios-field' : {
			required :  "Ingrese un minimo de 10 caracteres",
			minlength: 10
		    }
		},
		submitHandler: function() {
		    $('#myModal').modal({
			backdrop: false
		    });
		}
	    });
	},

	init: function(){
	    this.get();
	}
    },

    init: function(){
	this.validate.init();
    }
}

voluntariosController.init();